﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Waker.Common;

namespace Waker
{
    public partial class ChangePwdForm : Base.FormBasePop
    {
        public ChangePwdForm()
        {
            InitializeComponent();
        }

        private void ChangePwdForm_Load(object sender, EventArgs e)
        {
            labUserCode.Text = Session._CurrUserName;
            //hardwareInfo = Util.GetHardwareInfo();
        }

        protected override void FormSave()
        {
            if (!CheckInput())
            {
                return;
            }
            var bal = new BAL.BAL_SystemSetting();
            if (!bal.CheckUserByPasswod(Session._CurrUserCode, txtOldPwd.Text))
            {
                UI.ShowError("旧密码错误", "错误");
                txtOldPwd.Focus();
                return;
            }
            if (bal.ChangeUserPassword(Session._CurrUserCode, txtPwd.Text))
            {
                UI.ShowInfo("修改密码成功。请牢记您的新密码，\n下次登录将启用新密码！", "信息");
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                UI.ShowError("修改密码失败", "信息");
            }
        }
        private bool CheckInput()
        {
            base.errorPop.ClearErrors();
            if (!txtPwd.Text.Equals(txtPwd2.Text))
            {
                base.errorPop.SetError(txtPwd2, "两次密码不一致");
                txtPwd.Text = "";
                txtPwd2.Text = "";
                txtPwd.Focus();
                return false;
            }
            return true;
        }
    }
}